package com.wzy.dao;

import com.wzy.pojo.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDaoImpl implements UserDao {
    @Autowired
    private QueryRunner runner;
    public User findUser(User user) {

        try {
            return runner.query("select * from login where name= ?",new BeanHandler<User>(User.class), user.getName());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void addUser(User user) {
        try {
            runner.update(" insert into login (name, password,phone) values (?,?,?)",user.getName(),user.getPassword(),user.getPhone());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public User findUserinfo(User user) {

        try {
            return runner.query("select * from login where phone=?",new BeanHandler<User>(User.class), user.getPhone());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
